package routers

import (
	"HTdatapro/controllers"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

func init() {
	var FilterUser = func(c *context.Context) {
		if c.Request.RequestURI == "/login" {
			return
		}
		_, ok := c.Input.Session("uid").(int)
		if !ok {
			c.Redirect(302, "/login")
		}
	}

	beego.InsertFilter("*", beego.BeforeRouter, FilterUser)
	beego.Router("/", &controllers.MainController{})
	beego.Router("/index_v1.html", &controllers.MainController{}, "*:Index_v1")
	beego.Router("/login", &controllers.MainController{}, "*:Login")
	beego.Router("/logout", &controllers.MainController{}, "*:Logout")


	//Node
	beego.Router("/node/list_html/*", &controllers.NodeController{}, "*:HTNodeList_html")
	beego.Router("/node/list", &controllers.NodeController{}, "*:HTNodeList")
	beego.Router("/node/detail", &controllers.NodeController{}, "*:HTNodeDetail")
	beego.Router("/node/add", &controllers.NodeController{}, "*:HTNodeAdd")
	beego.Router("/node/update", &controllers.NodeController{}, "*:HTNodeUpdate")
	beego.Router("/node/delete", &controllers.NodeController{}, "*:HTNodeDelete")
	beego.Router("/node/multitextimageUp", &controllers.NodeController{}, "*:HTNodeMutiTextImageUp")

	//Record
	beego.Router("/record/list_html/*", &controllers.RecordController{}, "*:HTRecordList_html")
	beego.Router("/record/list", &controllers.RecordController{}, "*:HTRecordList")
	beego.Router("/record/detail", &controllers.RecordController{}, "*:HTRecordDetail")
	beego.Router("/record/add", &controllers.RecordController{}, "*:HTRecordAdd")
	beego.Router("/record/update", &controllers.RecordController{}, "*:HTRecordUpdate")
	beego.Router("/record/delete", &controllers.RecordController{}, "*:HTRecordDelete")
	beego.Router("/record/changestatus", &controllers.RecordController{}, "*:HTRecordStatusChange")

	//User
	beego.Router("/user/list_html/*", &controllers.UserController{}, "*:HTUserList_html")
	beego.Router("/user/list", &controllers.UserController{}, "*:HTUserList")
	beego.Router("/user/detail", &controllers.UserController{}, "*:HTUserDetail")
	beego.Router("/user/add", &controllers.UserController{}, "*:HTUserAdd")
	beego.Router("/user/update", &controllers.UserController{}, "*:HTUserUpdate")
	beego.Router("/user/delete", &controllers.UserController{}, "*:HTUserDelete")


	//hd
	beego.Router("/hd/node", &controllers.NodeController{}, "*:HDGetNodePage")
	beego.Router("/hd/node/update", &controllers.NodeController{}, "*:HDNodeUpdate")
	beego.Router("/hd/node/add", &controllers.NodeController{}, "*:HDNodeAdd")
	beego.Router("/hd/node/parentlist", &controllers.NodeController{}, "*:HDParentNodeListGetPage")
	beego.Router("/hd/node/childlist", &controllers.NodeController{}, "*:HDChildNodeListGetPage")


	beego.Router("/hd/recordlist", &controllers.RecordController{}, "*:HDRecordList")
	beego.Router("/hd/editlist", &controllers.RecordController{}, "*:HDEditList")
}
